package com.example.springboot.aop;

import com.example.springboot.document.ResultBo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Description: AOP统一返回后端返回值格式
 * @Author wenlinyu
 * @Date: 2020/12/21 15:13
 * @Version 1.0
 */
@Component
@Aspect
public class ResultAspect {

    @Pointcut("execution(public com.example.springboot.document.ResultBo *(..))")
    public void resultAspect() {

    }

    @Around("resultAspect()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            return joinPoint.proceed();
        } catch (Exception ex) {
            return new ResultBo<>(ex);
        }
    }
}
